﻿using System;
using System.Collections.Generic;
using System.Data.Entity.ModelConfiguration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NCT.MRS.DataAccessLayer.Entities;

namespace NCT.MRS.DataAccessLayer.Configurations
{
    public class TestTypeConfiguration : EntityTypeConfiguration<TestType>
    {
        public TestTypeConfiguration()
        {
            HasKey(P => P.Id);
            Property(P => P.Name).IsRequired().HasMaxLength(30);
            Property(P => P.NormalResult).IsOptional().HasMaxLength(250);
            Property(P => P.Price).IsRequired();
            Property(P => P.Code).IsRequired().HasMaxLength(30);
            Property(P => P.IsActive).IsRequired();

            HasOptional(P => P.ParentTestType).WithMany(P => P.ChildTestTypes).HasForeignKey(P => P.ParentTestId);
            HasMany(P => P.ChildTestTypes).WithOptional(P => P.ParentTestType).HasForeignKey(P => P.ParentTestId);

            HasRequired(P => P.Section).WithMany(P => P.TestTypes).HasForeignKey(P => P.SectionId);
            HasMany(P => P.TestPackages).WithMany(P => P.TestTypes);
            HasMany(P => P.TestTypeResults).WithRequired(P => P.TestType).HasForeignKey(P => P.TestTypeId);

            HasRequired(P => P.ModifiedByUser).WithMany().HasForeignKey(P => P.ModifiedByUserId).WillCascadeOnDelete(false);
        }
    }
}
